package Thread;
class Counter{
    private  int count =0;
    public  void  add(){
        synchronized (this){
            count++;
        }
    }
    public  int get(){
        return  count;
    }
}
public class Demo16 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (counter){
                    synchronized (counter){
                        synchronized (counter){
                            counter.add();
                        }
                    }
                }
            }
        });
        t1.start();
        t1.join();
        System.out.println("count = "+ counter.get());
    }
}
